package com.pda.xinma.presenter;

import com.pda.xinma.bean.OutSignBean;
import com.pda.xinma.contract.OutSignContract;
import com.pda.xinma.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import io.reactivex.functions.Consumer;

public class OutSignPresenter extends BasePresenter<OutSignContract .View> implements OutSignContract.Presenter {

    @Override
    public void getInfoByContainer(String container) {
        NetUtils.geApi().getInfoByContainer(container)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<OutSignBean>>() {
                    @Override
                    public void accept(BaseAppEntity<OutSignBean> outSignBeanBaseAppEntity) throws Exception {
                        getView().setData(outSignBeanBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void deliverySignFor(String rollerId, String container) {
        NetUtils.geApi().deliverySignFor(rollerId, container)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<OutSignBean>>() {
                    @Override
                    public void accept(BaseAppEntity<OutSignBean> outSignBeanBaseAppEntity) throws Exception {
                            getView().onSuccess();
                            getView().showMessage(outSignBeanBaseAppEntity.getMsg());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
